package com.xyh.flowershop.controller;

import com.xyh.flowershop.service.GoodsService;
import com.xyh.flowershop.service.SwipersService;
import com.xyh.flowershop.service.TypeService;
import com.xyh.flowershop.vo.req.goods.GoodPageReqVo;
import com.xyh.flowershop.vo.resp.common.ResultRespVo;
import com.xyh.flowershop.vo.resp.index.SwiperRespVo;
import com.xyh.flowershop.vo.resp.index.TypeIndexRespVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 小约翰可汗
 * @className AppIndexController 小程序首页的数据
 * @createTime 2024/3/3120:40
 */
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/appIndex/")
@Tag(name = "小程序首页接口")
public class AppIndexController {

    private final SwipersService swipersService;

    private final TypeService typeService;

    private final GoodsService goodsService;

    public AppIndexController(SwipersService swipersService, TypeService typeService, GoodsService goodsService) {
        this.swipersService = swipersService;
        this.typeService = typeService;
        this.goodsService = goodsService;
    }

    /**
     * 获取轮播图的数据
     * @return
     */
    @GetMapping("swiper")
    @Operation(description = "获取首页轮播图数据")
    public ResultRespVo findSwiperList(){
        List<SwiperRespVo> swiperRespVos = swipersService.getSwiperList();

        return ResultRespVo.success(200, "处理成功", swiperRespVos);

    }

    /**
     * 获取首页的分类目录
     * @return
     */
    @GetMapping("types")
    @Operation(description = "获取首页的一级目录")
    public ResultRespVo findTypeList(){
        List<TypeIndexRespVo> types = typeService.getTypeList();

        return ResultRespVo.success(200, "处理成功", types);
    }

    @GetMapping("hot")
    @Operation(description = "获得热门商品")
    public ResultRespVo findHotGoods(){
        GoodPageReqVo vo = new GoodPageReqVo();
        vo.setIsHot(true);
        vo.setPageIndex(1L);
        vo.setPageSize(100L);
        return ResultRespVo.success(goodsService.findPageGoods(vo));
    }
}
